﻿@using si.caha.Repository;

@{
    Layout = "/tpl/_layout.cshtml";
    PageData["PageTitle"] = "Delete category? Beware - all items of this category will be deleted!";

    if (IsPost)
    {
        int id = UrlData[0].IsInt() ? UrlData[0].AsInt() : 0;
        
        var dataContext = new DataContext();
        var categoryRepository = new CategoryRepository(dataContext);
        var error = categoryRepository.Delete(id);
        
        if (error.Length == 0)
        {
            Response.Redirect("~/Admin/Categories");
        }
        else
        {
            PageData["PageTitle"] = error;
        }
    }
}
<form method="post" action="">
    <input type="submit" value="Confirm" />
</form>
<a href="@Href("~/Admin/Categories")">Go back</a>